"""
文件名: ZX_OmsCartItemController.py
作用: 购物车管理模块的接口,每一个接口都有一个对应的方法,该方法用于测试用例
作者: 健哥
"""

from Untils.SendMethod import SendMethod
from Interface.DHX_MemberInterface import MemberInterface


class OmsCartItemController:
    def __init__(self):
        self.url = 'http://139.159.146.104:8083'

    member = MemberInterface()
    headers = member.get_token(username='liar', password='123456')

    def get_auth_code(self):
        """
        添加购物车
        :return:
        """
        payload = {
            "createDate": "2022-05-30T02:12:59.608Z",
            "deleteStatus": 0,
            "id": 0,
            "memberId": 2,
            "modifyDate": "2022-05-30T02:12:59.608Z",
            "price": 2699,
            "productAttr": '[{"key":"颜色","value":"黑色"},{"key":"容量","value":"32G"}]',
            "productBrand": "小米",
            "productCategoryId": 0,
            "productId": 27,
            "productName": "小米8 全面屏游戏智能手机 6GB+64GB 黑色 全网通4G 双卡双待",
            "productPic": "shenzhen.aliyuncs.com/mall/images/20180615/xiaomi.jpg",
            "productSkuCode": "201808270027001",
            "productSkuId": 98,
            "productSn": "7437788",
            "productSubTitle": "骁龙845处理器，红外人脸解锁，AI变焦双摄，AI语音助手小米6X低至1299，点击抢购",
            "quantity": 1
        }
        # 请求地址
        url = self.url + "/cart/add"
        # 请求数据
        return SendMethod.send_method(method='post', url=url, json=payload, headers=self.headers)

    def cart_clear(self):
        """
        清空购物车
        :param payload:
        :param username:
        :param password:
        :return:
        """
        url = self.url + "/cart/clear"
        # 请求数据
        return SendMethod.send_method(method='post', url=url, headers=self.headers)

    def cart_delete(self, payload):
        url = self.url + "/cart/delete"
        # 请求数据
        return SendMethod.send_method(method='post', url=url, data=payload, headers=self.headers)

    def cart_getproduct(self, payload):
        """
        获取购物车中某个商品的规格,用于重选规格
        :param username:
        :param password:
        :param payload:
        :return:
        """
        url = self.url + f"/cart/getProduct/{payload}"
        # 请求数据
        return SendMethod.send_method(method='get', url=url, headers=self.headers)

    def cart_list(self):
        """
        获取某个会员的购物车列表
        :param username:
        :param password:
        :param payload:
        :return:
        """
        url = self.url + '/cart/list'
        return SendMethod.send_method(method='get', url=url, headers=self.headers)

    def cart_update(self, payload):
        """
        修改购物车中商品的规格
        :param username:
        :param password:
        :param payload:
        :return:
        """
        url = self.url + '/cart/update/attr'
        return SendMethod.send_method(method='post', url=url, json=payload, headers=self.headers)

    def cart_update_quantity(self, payload):
        """
        修改购物车中某个商品的数量
        :param username:
        :param password:
        :return:
        """
        url = self.url + '/cart/update/quantity'
        return SendMethod.send_method(method='get', url=url, params=payload, headers=self.headers)

    def cart_list_promotion(self):
        """
        获取某个会员的购物车列表,包括促销信息
        :return:
        """
        url = self.url + '/cart/list/promotion'
        return SendMethod.send_method(method='get', url=url, headers=self.headers)


if __name__ == '__main__':
    occ = OmsCartItemController()
    # print(occ.cart_list())
    print(occ.get_auth_code())
